package com.cyanite.playlv2api.parsers.json;

import com.cyanite.playlv2api.types.Task;

import org.json.JSONException;
import org.json.JSONObject;

public class TaskParser extends AbstractParser<Task> {

    @Override
    public Task parse(JSONObject json) throws JSONException {

        Task obj = new Task();
        if (json.has("sid")) {
            obj.setId(json.getString("sid"));
        }
        if (json.has("tid")) {
            obj.setTripId(json.getString("tid"));
        }
        if (json.has("uid")) {
            obj.setUserId(json.getString("uid"));
        }
        if (json.has("nick")) {
            obj.setUserName(json.getString("nick"));
        }
        if (json.has("avatar")) {
            obj.setUserPhoto(json.getString("avatar"));
        }
        if (json.has("vid")) {
            obj.setVenueId(String.valueOf(json.getInt("vid")));
        }
        if (json.has("vname")) {
            obj.setVenueName(json.getString("vname"));
        }
        if (json.has("date")) {
            obj.setPostDate(json.getString("date"));
        }
        if (json.has("type")) {
            obj.setTaskCategoryId(json.getString("type"));
        }
        if (json.has("info")) {
            obj.setInfo(new InfoParser().parse(json.getJSONObject("info")));
        }
        if (json.has("way")) {
            obj.setAccessway(json.getInt("way"));
        }
        if (json.has("secret")) {
            obj.setSecretLevel(json.getInt("secret"));
        }
        if (json.has("photo")) {
            obj.setPhoto(json.getString("photo"));
        }
        if (json.has("tips")) {
            obj.setTipsCount(json.getInt("tips"));
        }
        if (json.has("tid")) {
            obj.setTripId(json.getString("tid"));
        }
        if (json.has("tname")) {
            obj.setTripName(json.getString("tname"));
        }
        if (json.has("distance")) {
            obj.setDistance(json.getInt("distance"));
        }
        return obj;
    }
}